//
//  RCServerActivityListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-28.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCServerActivityListDataModel.h"
#import "KFObjectExtension.h"


@implementation RCServerActivityItemDataModel

@synthesize aID = _aID;
@synthesize picUrl    = _picUrl;
@synthesize originalprice = _originalprice;
@synthesize title =_title;
@synthesize num    = _num;
@synthesize presentprice   = _presentprice;
@synthesize datetime= _datetime;


- (void) dealloc
{
    KF_RELEASE_SAFELY(_aID);
    KF_RELEASE_SAFELY(_picUrl);
    KF_RELEASE_SAFELY(_title);
    KF_RELEASE_SAFELY(_originalprice);
    KF_RELEASE_SAFELY(_num);
    KF_RELEASE_SAFELY(_presentprice);
    KF_RELEASE_SAFELY(_datetime);
    [super dealloc];
}
@end


@implementation RCServerActivityListDataModel
// 将JSON数据解析为数据模型
+(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    RCServerActivityListDataModel *retObject = [[[RCServerActivityListDataModel alloc] init] autorelease];
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCServerActivityItemDataModel *item = [[RCServerActivityItemDataModel alloc] init];
        item.aID = [dic stringValueForKey:@"aid" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.title = [dic stringValueForKey:@"title" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.picUrl = [dic stringValueForKey:@"picurl" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.originalprice = [dic stringValueForKey:@"originalprice" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.presentprice = [dic stringValueForKey:@"presentprice" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.num = [dic stringValueForKey:@"num" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.datetime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    return retObject;
}
@end
